Data Source: https://ephtracking.cdc.gov/DataExplorer/ (Select Community Design > Access to Parks and Elementary schools > Percent of Population Living Within Half Mile of Park, for Michigan by county)

Background: In recent years, physicians and public health officials have started to recognize the importance of time outside to the overall health of a person. Some doctors have even started prescribing time outdoors like they would a medication (Here’s a news article about this phenomenon - https://news.trust.org/item/20210831100001-qppwk/ )

I was interested to see how many people in Michigan have easy access to a park, and whether the percentage of people with access to parks has changed over recent years. I thought the best way to look at the data might be through a map of Michigan counties, color coded based on the percentage of people living in those counties that live within half a mile of a park. To take it one step further, I also calculated the change in that percentage between 2010 and 2015 for each county, and created a third map that shows which counties have had largest change in the percentage of people living near a park. If I was a park or city planner, I might look to the counties with the highest percentage or largest increase to see what they’re doing right.

park<-read.csv('data_202233.csv') #Read data in and format for 2010, 2015, and change between the two
park_2010 <-subset(park, Year == 2010)
park_2015 <-subset(park, Year == 2015)
parkval_2010<-as.numeric(sub("%", "", park_2010$Value))
parkval_2015<-as.numeric(sub("%", "", park_2015$Value))
library(ggplot2)
map=map_data("county", "michigan") #Pull in Michigan map
#Mapping each county in the park data set to the corresponding county in the map file
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#Create data frames for 2010, 2015, and change between the two
df.2010<-data.frame(park_2010$County, parkval_2010)
df.2015<-data.frame(park_2015$County, parkval_2015)
parkchange<-df.2015$parkval_2015-df.2010$parkval_2010
park_chg_df<-data.frame(unique(park$County), parkchange)

#Bind the park counties to the map counties
cbind(df.2010$County, unique(map$subregion))
##       [,1]            
##  [1,] "alcona"        
##  [2,] "alger"         
##  [3,] "allegan"       
##  [4,] "alpena"        
##  [5,] "antrim"        
##  [6,] "arenac"        
##  [7,] "baraga"        
##  [8,] "barry"         
##  [9,] "bay"           
## [10,] "benzie"        
## [11,] "berrien"       
## [12,] "branch"        
## [13,] "calhoun"       
## [14,] "cass"          
## [15,] "charlevoix"    
## [16,] "cheboygan"     
## [17,] "chippewa"      
## [18,] "clare"         
## [19,] "clinton"       
## [20,] "crawford"      
## [21,] "delta"         
## [22,] "dickinson"     
## [23,] "eaton"         
## [24,] "emmet"         
## [25,] "genesee"       
## [26,] "gladwin"       
## [27,] "gogebic"       
## [28,] "grand traverse"
## [29,] "gratiot"       
## [30,] "hillsdale"     
## [31,] "houghton"      
## [32,] "huron"         
## [33,] "ingham"        
## [34,] "ionia"         
## [35,] "iosco"         
## [36,] "iron"          
## [37,] "isabella"      
## [38,] "jackson"       
## [39,] "kalamazoo"     
## [40,] "kalkaska"      
## [41,] "kent"          
## [42,] "keweenaw"      
## [43,] "lake"          
## [44,] "lapeer"        
## [45,] "leelanau"      
## [46,] "lenawee"       
## [47,] "livingston"    
## [48,] "luce"          
## [49,] "mackinac"      
## [50,] "macomb"        
## [51,] "manistee"      
## [52,] "marquette"     
## [53,] "mason"         
## [54,] "mecosta"       
## [55,] "menominee"     
## [56,] "midland"       
## [57,] "missaukee"     
## [58,] "monroe"        
## [59,] "montcalm"      
## [60,] "montmorency"   
## [61,] "muskegon"      
## [62,] "newaygo"       
## [63,] "oakland"       
## [64,] "oceana"        
## [65,] "ogemaw"        
## [66,] "ontonagon"     
## [67,] "osceola"       
## [68,] "oscoda"        
## [69,] "otsego"        
## [70,] "ottawa"        
## [71,] "presque isle"  
## [72,] "roscommon"     
## [73,] "saginaw"       
## [74,] "st clair"      
## [75,] "st joseph"     
## [76,] "sanilac"       
## [77,] "schoolcraft"   
## [78,] "shiawassee"    
## [79,] "tuscola"       
## [80,] "van buren"     
## [81,] "washtenaw"     
## [82,] "wayne"         
## [83,] "wexford"
df.2010$County=unique(map$subregion)

cbind(df.2015$County, unique(map$subregion))
##       [,1]            
##  [1,] "alcona"        
##  [2,] "alger"         
##  [3,] "allegan"       
##  [4,] "alpena"        
##  [5,] "antrim"        
##  [6,] "arenac"        
##  [7,] "baraga"        
##  [8,] "barry"         
##  [9,] "bay"           
## [10,] "benzie"        
## [11,] "berrien"       
## [12,] "branch"        
## [13,] "calhoun"       
## [14,] "cass"          
## [15,] "charlevoix"    
## [16,] "cheboygan"     
## [17,] "chippewa"      
## [18,] "clare"         
## [19,] "clinton"       
## [20,] "crawford"      
## [21,] "delta"         
## [22,] "dickinson"     
## [23,] "eaton"         
## [24,] "emmet"         
## [25,] "genesee"       
## [26,] "gladwin"       
## [27,] "gogebic"       
## [28,] "grand traverse"
## [29,] "gratiot"       
## [30,] "hillsdale"     
## [31,] "houghton"      
## [32,] "huron"         
## [33,] "ingham"        
## [34,] "ionia"         
## [35,] "iosco"         
## [36,] "iron"          
## [37,] "isabella"      
## [38,] "jackson"       
## [39,] "kalamazoo"     
## [40,] "kalkaska"      
## [41,] "kent"          
## [42,] "keweenaw"      
## [43,] "lake"          
## [44,] "lapeer"        
## [45,] "leelanau"      
## [46,] "lenawee"       
## [47,] "livingston"    
## [48,] "luce"          
## [49,] "mackinac"      
## [50,] "macomb"        
## [51,] "manistee"      
## [52,] "marquette"     
## [53,] "mason"         
## [54,] "mecosta"       
## [55,] "menominee"     
## [56,] "midland"       
## [57,] "missaukee"     
## [58,] "monroe"        
## [59,] "montcalm"      
## [60,] "montmorency"   
## [61,] "muskegon"      
## [62,] "newaygo"       
## [63,] "oakland"       
## [64,] "oceana"        
## [65,] "ogemaw"        
## [66,] "ontonagon"     
## [67,] "osceola"       
## [68,] "oscoda"        
## [69,] "otsego"        
## [70,] "ottawa"        
## [71,] "presque isle"  
## [72,] "roscommon"     
## [73,] "saginaw"       
## [74,] "st clair"      
## [75,] "st joseph"     
## [76,] "sanilac"       
## [77,] "schoolcraft"   
## [78,] "shiawassee"    
## [79,] "tuscola"       
## [80,] "van buren"     
## [81,] "washtenaw"     
## [82,] "wayne"         
## [83,] "wexford"
df.2015$County=unique(map$subregion)

cbind(park_chg_df$County, unique(map$subregion))
##       [,1]            
##  [1,] "alcona"        
##  [2,] "alger"         
##  [3,] "allegan"       
##  [4,] "alpena"        
##  [5,] "antrim"        
##  [6,] "arenac"        
##  [7,] "baraga"        
##  [8,] "barry"         
##  [9,] "bay"           
## [10,] "benzie"        
## [11,] "berrien"       
## [12,] "branch"        
## [13,] "calhoun"       
## [14,] "cass"          
## [15,] "charlevoix"    
## [16,] "cheboygan"     
## [17,] "chippewa"      
## [18,] "clare"         
## [19,] "clinton"       
## [20,] "crawford"      
## [21,] "delta"         
## [22,] "dickinson"     
## [23,] "eaton"         
## [24,] "emmet"         
## [25,] "genesee"       
## [26,] "gladwin"       
## [27,] "gogebic"       
## [28,] "grand traverse"
## [29,] "gratiot"       
## [30,] "hillsdale"     
## [31,] "houghton"      
## [32,] "huron"         
## [33,] "ingham"        
## [34,] "ionia"         
## [35,] "iosco"         
## [36,] "iron"          
## [37,] "isabella"      
## [38,] "jackson"       
## [39,] "kalamazoo"     
## [40,] "kalkaska"      
## [41,] "kent"          
## [42,] "keweenaw"      
## [43,] "lake"          
## [44,] "lapeer"        
## [45,] "leelanau"      
## [46,] "lenawee"       
## [47,] "livingston"    
## [48,] "luce"          
## [49,] "mackinac"      
## [50,] "macomb"        
## [51,] "manistee"      
## [52,] "marquette"     
## [53,] "mason"         
## [54,] "mecosta"       
## [55,] "menominee"     
## [56,] "midland"       
## [57,] "missaukee"     
## [58,] "monroe"        
## [59,] "montcalm"      
## [60,] "montmorency"   
## [61,] "muskegon"      
## [62,] "newaygo"       
## [63,] "oakland"       
## [64,] "oceana"        
## [65,] "ogemaw"        
## [66,] "ontonagon"     
## [67,] "osceola"       
## [68,] "oscoda"        
## [69,] "otsego"        
## [70,] "ottawa"        
## [71,] "presque isle"  
## [72,] "roscommon"     
## [73,] "saginaw"       
## [74,] "st clair"      
## [75,] "st joseph"     
## [76,] "sanilac"       
## [77,] "schoolcraft"   
## [78,] "shiawassee"    
## [79,] "tuscola"       
## [80,] "van buren"     
## [81,] "washtenaw"     
## [82,] "wayne"         
## [83,] "wexford"
park_chg_df$County=unique(map$subregion)
#join into map data sets
colnames(map)[6]<-'County'
park_map_2010<-left_join(map, df.2010, by=c('County'))
park_map_2015<-left_join(map, df.2015, by=c('County'))
park_map_chg<-left_join(map, park_chg_df, by=c('County'))
#2010 Map
library(plotly)
## Warning: package 'plotly' was built under R version 4.1.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
gm1<-ggplot(park_map_2010, aes(x=long, y=lat, group=group, text=paste("County:",County, "<br>% Residents:", parkval_2010)))+geom_polygon(aes(fill=parkval_2010))+coord_map()+scale_fill_viridis_b(option='plasma')+labs(title="% County Residents living within half mile of a park \n 2010")+theme(plot.title=element_text(hjust=0.5))+theme(axis.title.x = element_blank())+theme(axis.title.y = element_blank())+labs(fill="% Residents")
gm1<-ggplotly(gm1, tooltip = 'text')
gm1
#2015 Map
library(plotly)
gm2<-ggplot(park_map_2015, aes(x=long, y=lat, group=group, text= paste("County:",County, "<br>% Residents:", parkval_2015)))+geom_polygon(aes(fill=parkval_2015))+coord_map()+scale_fill_viridis_b(option='plasma')+labs(title="% County Residents living within half mile of a park \n 2015")+theme(plot.title=element_text(hjust=0.5))+theme(axis.title.x = element_blank())+theme(axis.title.y = element_blank())+labs(fill="% Residents")
gm2<-ggplotly(gm2, tooltip='text')
gm2
#Change Map
library(plotly)
gm3<-ggplot(park_map_chg, aes(x=long, y=lat, group=group, text= paste("County:", County, "<br> Change in % Residents:", parkchange)))+geom_polygon(aes(fill=parkchange))+coord_map()+scale_fill_viridis_b(option='turbo')+labs(title="Change in \n % County Residents living within half mile of a park \n 2010-2015")+theme(plot.title=element_text(hjust=0.5))+theme(axis.title.x = element_blank())+theme(axis.title.y = element_blank())+labs(fill="Change in % of Residents")
gm3<-ggplotly(gm3, tooltip = 'text')
gm3